package com.sky.mapper;

import com.sky.entity.SetmealDish;
import com.sky.vo.DishItemVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SetmealDishMapper {

    /**
     * 根据菜品id查询 套餐菜品关系表中是否有套餐包含了这个菜品 并用聚合函数统计数量
     * @param ids
     * @return
     */
    Long countByDishIds(@Param("ids") List<Long> ids);

    /**
     * 插入套餐包含的菜品信息
     * @param setmealDish
     */
    @Insert("insert into setmeal_dish values (null, #{setmealId}, #{dishId}, #{name}, " +
            "#{price}, #{copies})")
    void insertSetmealInfo(SetmealDish setmealDish);

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Select("select * from setmeal_dish where setmeal_id = #{id}")
    List<SetmealDish> selectBySetmealId(Long id);

    /**
     * 删除套餐对应的菜品信息
     * @param id
     */
    @Delete("delete from setmeal_dish where setmeal_id = #{id}")
    void deleteBySetmealId(Long id);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("select * from setmeal_dish where dish_id = #{id}")
    List<SetmealDish> selectByDishId(Long id);

    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> selectSetmealDish(Long setmealId);
}
